/*
 * VentanaPrincipal.java
 *
 * Created on 06-dic-2011, 13:02:34
 */

package interfazgrafica;

import interfazgrafica.ayuda.*;

/**
 * Clase que muestra el acceso a la aplicacion.
 * @author Lauaa
 */
public class VentanaPrincipal extends javax.swing.JFrame {

    String[] args;
    public static VentanaPrincipal ven = new VentanaPrincipal();

    /** Creates new form VentanaPrincipal */
    public VentanaPrincipal() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPasswordFieldCampoContraseña = new javax.swing.JPasswordField();
        jToggleButtonEnter = new javax.swing.JToggleButton();
        jLabelContraseña = new javax.swing.JLabel();
        jButtonAyuda = new javax.swing.JButton();
        jLabelUsuario = new javax.swing.JLabel();
        jTextFieldCampoUsuario = new javax.swing.JTextField();
        jLabelTitulo = new javax.swing.JLabel();
        jLabelVaca = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(cowmanager.CowManagerApp.class).getContext().getResourceMap(VentanaPrincipal.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setBackground(resourceMap.getColor("Form.background")); // NOI18N
        setForeground(resourceMap.getColor("Form.foreground")); // NOI18N
        setName("Form"); // NOI18N

        jPasswordFieldCampoContraseña.setText(resourceMap.getString("jPasswordFieldCampoContraseña.text")); // NOI18N
        jPasswordFieldCampoContraseña.setName("jPasswordFieldCampoContraseña"); // NOI18N

        jToggleButtonEnter.setIcon(resourceMap.getIcon("jToggleButtonEnter.icon")); // NOI18N
        jToggleButtonEnter.setSelected(true);
        jToggleButtonEnter.setText(resourceMap.getString("jToggleButtonEnter.text")); // NOI18N
        jToggleButtonEnter.setName("jToggleButtonEnter"); // NOI18N
        jToggleButtonEnter.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jToggleButtonEnterActionPerformed(evt);
            }
        });

        jLabelContraseña.setFont(resourceMap.getFont("jLabelContraseña.font")); // NOI18N
        jLabelContraseña.setText(resourceMap.getString("jLabelContraseña.text")); // NOI18N
        jLabelContraseña.setName("jLabelContraseña"); // NOI18N

        jButtonAyuda.setIcon(resourceMap.getIcon("jButtonAyuda.icon")); // NOI18N
        jButtonAyuda.setText(resourceMap.getString("jButtonAyuda.text")); // NOI18N
        jButtonAyuda.setName("jButtonAyuda"); // NOI18N
        jButtonAyuda.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAyudaActionPerformed(evt);
            }
        });

        jLabelUsuario.setFont(resourceMap.getFont("jLabelUsuario.font")); // NOI18N
        jLabelUsuario.setText(resourceMap.getString("jLabelUsuario.text")); // NOI18N
        jLabelUsuario.setName("jLabelUsuario"); // NOI18N

        jTextFieldCampoUsuario.setText(resourceMap.getString("jTextFieldCampoUsuario.text")); // NOI18N
        jTextFieldCampoUsuario.setName("jTextFieldCampoUsuario"); // NOI18N
        jTextFieldCampoUsuario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldCampoUsuarioActionPerformed(evt);
            }
        });

        jLabelTitulo.setFont(resourceMap.getFont("jLabelTitulo.font")); // NOI18N
        jLabelTitulo.setText(resourceMap.getString("jLabelTitulo.text")); // NOI18N
        jLabelTitulo.setName("jLabelTitulo"); // NOI18N

        jLabelVaca.setIcon(resourceMap.getIcon("jLabelVaca.icon")); // NOI18N
        jLabelVaca.setLabelFor(jLabelVaca);
        jLabelVaca.setText(resourceMap.getString("jLabelVaca.text")); // NOI18N
        jLabelVaca.setDisabledIcon(resourceMap.getIcon("jLabelVaca.disabledIcon")); // NOI18N
        jLabelVaca.setName("jLabelVaca"); // NOI18N

        jLabel1.setIcon(resourceMap.getIcon("jLabel1.icon")); // NOI18N
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(98, 98, 98)
                                .addComponent(jLabelVaca)
                                .addGap(99, 99, 99)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                        .addComponent(jLabelUsuario)
                                        .addGap(18, 18, 18)
                                        .addComponent(jTextFieldCampoUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 257, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                        .addComponent(jLabelContraseña)
                                        .addGap(18, 18, 18)
                                        .addComponent(jPasswordFieldCampoContraseña, javax.swing.GroupLayout.DEFAULT_SIZE, 230, Short.MAX_VALUE)))
                                .addGap(18, 18, 18)
                                .addComponent(jToggleButtonEnter, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addGap(219, 219, 219)))
                        .addGap(126, 126, 126)
                        .addComponent(jButtonAyuda))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(38, 38, 38)
                        .addComponent(jLabelTitulo)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jButtonAyuda))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(88, 88, 88)
                                .addComponent(jLabelVaca, javax.swing.GroupLayout.PREFERRED_SIZE, 374, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(jLabelTitulo, javax.swing.GroupLayout.DEFAULT_SIZE, 67, Short.MAX_VALUE)
                                .addGap(143, 143, 143)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                            .addComponent(jLabelUsuario)
                                            .addComponent(jTextFieldCampoUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGap(72, 72, 72)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                            .addComponent(jLabelContraseña)
                                            .addComponent(jPasswordFieldCampoContraseña, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(25, 25, 25)
                                        .addComponent(jToggleButtonEnter, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGap(134, 134, 134)))
                        .addGap(41, 41, 41)
                        .addComponent(jLabel1)))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jTextFieldCampoUsuarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldCampoUsuarioActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldCampoUsuarioActionPerformed

    private void jToggleButtonEnterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButtonEnterActionPerformed
        String usuario = jTextFieldCampoUsuario.getText();
        String contraseña = new String(jPasswordFieldCampoContraseña.getPassword());
        String rol = Aplicacion.comprobar(usuario, contraseña);

        //Comprueba el rol de la persona para poder lanzar distintas aplicaciones
        //dependiendo del mismo.
        if(rol.compareTo("administrador") == 0){
            ven.setVisible(false);
            VentanaAdministrador.main(args);
        }
        else if(rol.compareTo("usuario") == 0){
            ven.setVisible(false);
            VentanaUsuario.main(args);
        }
        else if(rol.compareTo("") == 0){
            //ven.setVisible(false);
            ErrorLogin.main(args);
        }
    }//GEN-LAST:event_jToggleButtonEnterActionPerformed

    private void jButtonAyudaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAyudaActionPerformed
        VentanaAyuda ayuda = new VentanaAyuda("Aplicacion");
        ayuda.setVisible(true);
    }//GEN-LAST:event_jButtonAyudaActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                ven.setTitle("Gestión Ganadera");
                ven.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonAyuda;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabelContraseña;
    private javax.swing.JLabel jLabelTitulo;
    private javax.swing.JLabel jLabelUsuario;
    private javax.swing.JLabel jLabelVaca;
    private javax.swing.JPasswordField jPasswordFieldCampoContraseña;
    private javax.swing.JTextField jTextFieldCampoUsuario;
    private javax.swing.JToggleButton jToggleButtonEnter;
    // End of variables declaration//GEN-END:variables

}
